package com.itheima.demo1;

public class Damo23TwoDimensionalArray {
    //  遍历二维数组
    public static void print(int arr[][]) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
    //二维数组求和
    public static int sum(int arr[][]) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                sum += arr[i][j];
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        //动态初始化
        int arr[][] = new int[3][3];
        /*
        二维数组两个[[
        [[I@45ee12a7
        一维数组一个[
        [I@330bedb4
        */
//      二维数组地址值
        System.out.println(arr);
//      一维数组地址值
        System.out.println(arr[0]);
//      一维数组值

        //静态初始化
        int arr2[][] = new int[][] {{1,2},{3,4}};
        int arr1[][] = {{1, 2, 3, 4}, {5, 6, 7, 8}};
        System.out.println(arr[0][1]);
        print(arr1);
        System.out.println(sum(arr2));
    }
}
